﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YJKMaterialStatistic;

namespace YJKStatisticTable.AreaTable.Forms
{
	public partial class NetAreaStatisticalForm : System.Windows.Forms.Form
	{
		public NetAreaStatisticalForm()
		{
			this.InitializeComponent();
			this.cmbGrid.Items.Add("防火分区面积表");
			this.cmbGrid.Items.Add("主要经济技术指标表");
			this.cmbGrid.Items.Add("建筑物明细表");
			this.cmbGrid.SelectedIndex = 0;
			this.txtGridName.Text = "防火分区面积表";
			this.m_gridSet.GridName = this.txtGridName.Text;
		}

		private void NetAreaStatisticalForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
		}

		private void btnSet_Click(object sender, EventArgs e)
		{
			List<string> columnListInfo = this.GetColumnListInfo();
			DlgColumnSetCommon dlgColumnSetCommon = new DlgColumnSetCommon(this.cmbGrid.Text, this.m_strFileFolder, columnListInfo, ref this.m_gridSet);
			if (dlgColumnSetCommon.ShowDialog() == DialogResult.OK)
			{
				this.m_gridSet.SetColWidth = true;
			}
		}

		private List<string> GetColumnListInfo()
		{
			List<string> list = new List<string>();
			if (this.cmbGrid.Text == "防火分区面积表")
			{
				list.Add("楼层");
				list.Add("防火分区编号");
				list.Add("该区功能");
				list.Add("防火分区面积(㎡)");
				list.Add("人数计算指标");
				list.Add("计算人数(人)");
				list.Add("百人疏散指标");
				list.Add("计算宽度(m)");
				list.Add("独用楼梯宽度(没人)");
				list.Add("楼梯数量");
				list.Add("辅助宽度(每个)");
				list.Add("数量");
				list.Add("小计");
			}
			else if (!(this.cmbGrid.Text == "主要经济技术指标表") && this.cmbGrid.Text == "建筑物明细表")
			{
				list.Add("建筑物编号");
				list.Add("建筑物名称");
				list.Add("层数(地上\\地下)");
				list.Add("建筑高度(M)");
				list.Add("地上建筑面积(㎡)");
				list.Add("地下建筑面积(㎡)");
				list.Add("总建筑面积(㎡)");
			}
			return list;
		}

		private void btnDrawGrid_Click(object sender, EventArgs e)
		{
			this.m_gridSet.GridName = this.txtGridName.Text;
			this.m_gridSet.LinkFile = this.chkLink.Checked;
			this.m_gridSet.NewView = this.chkNewView.Checked;
			base.DialogResult = DialogResult.OK;
		}

		private void btnExcel_Click(object sender, EventArgs e)
		{
			SaveFileDialog saveFileDialog = new SaveFileDialog();
			saveFileDialog.FileName = this.txtGridName.Text;
			saveFileDialog.Filter = "Excel文件|*.xls|Excel文件|*.xlsx|盈建科表格文件|*.hybg";
			if (saveFileDialog.ShowDialog() == DialogResult.OK)
			{
				this.m_strFilePath = saveFileDialog.FileName;
				this.m_eFileType = saveFileDialog.FilterIndex;
				this.m_gridSet.GridName = this.txtGridName.Text;
				this.m_gridSet.LinkFile = this.chkLink.Checked;
				this.m_gridSet.NewView = this.chkNewView.Checked;
			}
			base.DialogResult = DialogResult.Yes;
		}

		private void Cancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void cmbGridType_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.txtGridName.Text = this.cmbGrid.Text;
			this.m_gridSet.GridName = this.txtGridName.Text;
			if (this.cmbGrid.Text == "主要经济技术指标表")
			{
				this.btnSet.Enabled = false;
				return;
			}
			this.btnSet.Enabled = true;
		}

		private void NetAreaStatisticalForm_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}

		private string m_strFileFolder = Path.Combine(Product.InstallLocation, "Templates", "NetAreaTempletlFile");

		public GridSetCommonInfo m_gridSet = new GridSetCommonInfo();

		public string m_strFilePath = "";

		public int m_eFileType;
	}
}
